package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendanceDedItemAddDTO;
import org.jsola.hr.dto.AttendanceDedItemUpdateDTO;
import org.jsola.hr.entity.AttendanceDedItemDO;
import org.jsola.hr.query.AttendanceDedItemQuery;
import org.jsola.hr.service.IAttendanceDedItemService;
import org.jsola.hr.vo.AttendanceDedItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendanceDedItemTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendanceDedItemService attendanceDedItemService;

    /**
     * 生成add测试数据
     * @return AttendanceDedItemAddDTO
     */
    public AttendanceDedItemAddDTO getAttendanceDedItemAddDTO(){
        AttendanceDedItemAddDTO attendanceDedItemAddDTO = new AttendanceDedItemAddDTO();
        attendanceDedItemAddDTO.setTimeOperator(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendanceDedItemAddDTO.setTimeValue(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceDedItemAddDTO.setCompanyId(getRandomValue("varchar",32));
        attendanceDedItemAddDTO.setParentId(getRandomValue("varchar",32));
        attendanceDedItemAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",10)));
        attendanceDedItemAddDTO.setLevel(SafeKit.getInteger(getRandomValue("int",10)));
        return attendanceDedItemAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendanceDedItemUpdateDTO
     */
    public AttendanceDedItemUpdateDTO getAttendanceDedItemUpdateDTO(AttendanceDedItemVO attendanceDedItemVO){
        return attendanceDedItemService.selectDOById(attendanceDedItemVO.getId(), SITE_ID).to(AttendanceDedItemUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendanceDedItemQuery
     */
    public AttendanceDedItemQuery getAttendanceDedItemQuery() {
        AttendanceDedItemQuery attendanceDedItemQuery = new AttendanceDedItemQuery();
        List<AttendanceDedItemDO> attendanceDedItemDOList = attendanceDedItemService.list(new AttendanceDedItemDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendanceDedItemDOList)) {
            AttendanceDedItemDO attendanceDedItemDO = attendanceDedItemDOList.get(0);
            attendanceDedItemQuery = attendanceDedItemDO.to(AttendanceDedItemQuery.class);
            if (attendanceDedItemDO.getGmtCreate() != null) {
                attendanceDedItemQuery.setGmtCreateStart(DateKit.getBeforeDay(attendanceDedItemDO.getGmtCreate(),-1));
                attendanceDedItemQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendanceDedItemDO.getGmtCreate(),1));
            }
            if (attendanceDedItemDO.getGmtModified() != null) {
                attendanceDedItemQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendanceDedItemDO.getGmtModified(),-1));
                attendanceDedItemQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendanceDedItemDO.getGmtModified(),1));
            }
        }
        return attendanceDedItemQuery;
    }

    /**
     * 保存示例
     * @return AttendanceDedItemVO
     */
    public AttendanceDedItemVO saveAttendanceDedItemExample(){
        AttendanceDedItemAddDTO addDTO = this.getAttendanceDedItemAddDTO();
        AttendanceDedItemVO attendanceDedItemVO = attendanceDedItemService.save(addDTO,buildTokenUser());
        return attendanceDedItemVO;
    }


}

